using System;
using System.Net.Sockets;

namespace ProxyServer.ProxyImpl
{
    public class HttpListener : Listener
    {
        private readonly ILogger logger = Logger.GetLogger();

        protected override void OnAccept(Socket acceptedSocket)
        {
            base.OnAccept(acceptedSocket);

            try
            {
                if (acceptedSocket != null)
                {
                    var newClient = new HttpClient(acceptedSocket, RemoveClient);

                    newClient.StartHandshake();
                    AddClient(newClient);

                    logger.Info("add a new client from"+newClient);
                }
            }
            catch (Exception e)
            {
                logger.Error("error adding a new client:" + e.Message);
            }
        }
    }
}